package com.xxd.spring.boot.demo.wubolin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.wubolin.Result;
import com.xxd.spring.boot.demo.wubolin.entity.Classes;
import com.xxd.spring.boot.demo.wubolin.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/classes")
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    @RequestMapping("/add")
    public Result add(@RequestBody Classes classes){
        classesService.add(classes);
        return new Result().success();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Classes classes){
        classesService.update(classes);
        return new Result().success();
    }

    @RequestMapping("/delete{id}")
    public Result detele(@PathVariable Integer id){
        classesService.delete(id);
        return new Result().success();
    }

    @RequestMapping("/listPage")
    public Result listPage(Page page, @RequestParam Map<String,Object> params){
        IPage resPage = classesService.listPage(page,params);
        return new Result().success().setData(resPage);
    }

    @RequestMapping("/list")
    public Result list(@RequestBody Map<String,Object> params){
        List<Classes> list = classesService.list(params);
        return new Result().success().setData(list);
    }

    @RequestMapping("/infoById/{id}")
    public Result infoById(@PathVariable("id") Integer id){
        Classes classes = classesService.infoById((id));
        return new Result().success().setData(classes);
    }

    @RequestMapping("/all")
    public Result all(){
        List<Classes> list = classesService.all();
        return new Result().success().setData(list);
    }
}
